class Solution(object):
    def flipLights(self, n, presses):
        """
        :type n: int
        :type presses: int
        :rtype: int
        """
        n = min(n, 6)

        def switch(t, state):
            out = [0] * n
            for i in range(n):
                if state == 0:
                    out[i] = 1 - t[i]
                if state == 1:
                    if i % 2 == 0:
                        out[i] = t[i]
                    else:
                        out[i] = 1 - t[i]
                if state == 2:
                    if i % 2 == 1:
                        out[i] = t[i]
                    else:
                        out[i] = 1 - t[i]
                if state == 3:
                    if i % 3 == 0:
                        out[i] = 1 - t[i]
                    else:
                        out[i] = t[i]
            return tuple(out)

        now = {tuple([1 for _ in range(n)])}
        k = 0
        while k < presses:
            k += 1
            next_set = set()
            for t in now:
                for state in range(4):
                    next_set.add(switch(t, state))
            now = next_set
        return len(now)


data = Solution()
n = 3
presses = 1
print(data.flipLights(n, presses))
